package test03;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class t3 {
    public static void main(String[] args) {
        // 1.定义Map集合
        HashMap<Student, String> map = new HashMap<>();
        map.put(new Student("st1", 19), "北京");
        map.put(new Student("st2", 22), "上海");
        map.put(new Student("st3", 49), "广州");
        map.put(new Student("st4", 9), "深圳");
        map.put(new Student("st5", 70), "厦门");

        //2、（一）四种放式遍历Map集合中的内容
        for (Map.Entry<Student, String> ST : map.entrySet()) {
            System.out.println(ST.getKey() + "---" + ST.getValue());
        }
        System.out.println("-----------------------------------------------");

        //3、（二）四种放式遍历Map集合中的内容
        Set<Map.Entry<Student, String>> set = map.entrySet();
        Iterator<Map.Entry<Student, String>> it = set.iterator();
        while (it.hasNext()) {
            Map.Entry<Student, String> entry = it.next();
            System.out.println(entry.getKey() + "---" + entry.getValue());
        }
        System.out.println("-----------------------------------------------");

        //4、（三）四种放式遍历Map集合中的内容
        for(Student student :map.keySet()) {
            String address = map.get(student);
            System.out.println(student+"---"+address);
        }
        System.out.println("-----------------------------------------------");

        //5、（四）四种放式遍历Map集合中的内容
        Set<Student> keySet = map.keySet();
        Iterator<Student> student2 = keySet.iterator();
        while(student2.hasNext()) {
            Student student = student2.next();
            String address = map.get(student);
            System.out.println(student+"---" + address);
        }
    }
}
